package test;

import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadVideoRequest;
import com.aliyun.vod.upload.resp.UploadVideoResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.RpcAcsRequest;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;

import java.util.List;

public class testVod {
    public static void main(String[] args) throws ClientException {
        //上传视频的方法
        String title="xbx";
        String fileName="C:\\Users\\bzzb\\Documents\\WeChat Files\\wxid_1h7fi7afhcpn22\\FileStorage\\Video\\2021-02\\fa2fc9326593d0384474790f2fa0b29d.mp4";
            UploadVideoRequest request = new UploadVideoRequest("LTAI4GGSeQKZXLZZnvUe9oU1", "4SS2gXBy0cgI9rhQMV1lBO3QifcKj1", title, fileName);
            /* 可指定分片上传时每个分片的大小，默认为2M字节 */
            request.setPartSize(2 * 1024 * 1024L);
            /* 可指定分片上传时的并发线程数，默认为1，(注：该配置会占用服务器CPU资源，需根据服务器情况指定）*/
            request.setTaskNum(1);
            UploadVideoImpl uploader = new UploadVideoImpl();
            UploadVideoResponse response = uploader.uploadVideo(request);
            System.out.print("RequestId=" + response.getRequestId() + "\n");  //请求视频点播服务的请求ID
            if (response.isSuccess()) {
                System.out.print("VideoId=" + response.getVideoId() + "\n");
            } else {
                /* 如果设置回调URL无效，不影响视频上传，可以返回VideoId同时会返回错误码。其他情况上传失败时，VideoId为空，此时需要根据返回错误码分析具体错误原因 */
                System.out.print("VideoId=" + response.getVideoId() + "\n");
                System.out.print("ErrorCode=" + response.getCode() + "\n");
                System.out.print("ErrorMessage=" + response.getMessage() + "\n");

            }
        }
//        //1.根据视频id获取视频地址和播放凭证
//        //创建初始话对象
//        DefaultAcsClient defaultAcsClient= initObject.initVodClient("LTAI4GGSeQKZXLZZnvUe9oU1","4SS2gXBy0cgI9rhQMV1lBO3QifcKj1");
//        //创建获取视频地址的request和response
//        GetPlayInfoRequest request=new GetPlayInfoRequest();
//        GetPlayInfoResponse response=new GetPlayInfoResponse();
//        //向request中设置id
//        request.setVideoId("f127ca07bc0848cd8e1aa7943ee43167");
//        //调用对象中的方法，传递request，获取最终结果
//        response=defaultAcsClient.getAcsResponse(request);
//        List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
//        //播放地址
//        for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
//            System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
//        }
//        //Base信息
//        System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
    }

